package com.wyth.study.advancedemo;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.TextView;

import com.wyth.study.advancedemo.widget.MyTextView;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class DispatchTestActivity extends AppCompatActivity implements View.OnTouchListener {
    private static final String TAG = "DispatchTestActivity";

    @BindView(R.id.act_dispatch_tv_mytv)
    MyTextView mTv;
    @BindView(R.id.act_dispatch_tv_mytv2)
    TextView actDispatchTvMytv2;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dispatchtest);
        ButterKnife.bind(this);
        initView();

    }

    @SuppressLint("ClickableViewAccessibility")
    private void initView() {
        mTv.setOnTouchListener(this);
    }

    @OnClick({R.id.act_dispatch_tv_mytv, R.id.act_dispatch_tv_mytv2})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.act_dispatch_tv_mytv:
                Log.d(TAG, "onViewClicked: 点击 view了");
                break;
            case R.id.act_dispatch_tv_mytv2:


                break;
        }
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent event) {
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                Log.d(TAG, "dispatchTouchEvent: ACTION_DOWN");

                break;
            case MotionEvent.ACTION_MOVE:
                Log.d(TAG, "dispatchTouchEvent: ACTION_MOVE");
                break;
            case MotionEvent.ACTION_UP:
                Log.d(TAG, "dispatchTouchEvent: ACTION_UP");
                break;
            case MotionEvent.ACTION_CANCEL:
                Log.d(TAG, "dispatchTouchEvent: ACTION_CANCEL");
                break;
        }
//        return true;
        return super.dispatchTouchEvent(event);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                Log.d(TAG, "onTouchEvent: ACTION_DOWN ");
                Log.d(TAG, "onTouchEvent: 应该到这里了 ");

                break;
            case MotionEvent.ACTION_MOVE:
                Log.d(TAG, "onTouchEvent: ACTION_MOVE ");
                break;
            case MotionEvent.ACTION_UP:
                Log.d(TAG, "onTouchEvent: ACTION_UP ");
                break;
            case MotionEvent.ACTION_CANCEL:
                Log.d(TAG, "onTouchEvent: ACTION_CANCEL ");
                break;
        }
        return super.onTouchEvent(event);
//        return false;
    }

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        switch (v.getId()) {
            case R.id.act_dispatch_tv_mytv:
                switch (event.getAction()) {
                    case MotionEvent.ACTION_DOWN:
                        Log.d(TAG, "onTouch: ACTION_DOWN ");

                        break;
                    case MotionEvent.ACTION_MOVE:
                        Log.d(TAG, "onTouch: ACTION_MOVE ");
                        break;
                    case MotionEvent.ACTION_UP:
                        Log.d(TAG, "onTouch: ACTION_UP ");
                        break;
                    case MotionEvent.ACTION_CANCEL:
                        Log.d(TAG, "onTouch: ACTION_CANCEL ");
                        break;
                }

                break;
        }
        return false;
    }
}
